﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ecommerce.Model;
using System.Web.UI.HtmlControls;
using Ecommerce.Web.Code;

namespace Ecommerce.Web
{
    public partial class SiteInfo : BaseMaster
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.CarregarCategorias();
            }

            dvBemVindo.InnerText = "Bem vindo " + this.NomeUsuarioLogado;
        }

        private void CarregarCategorias()
        {
            CategoriaModel categoriaModel = new CategoriaModel();
            List<tb_cat_categoria> listaCategorias = categoriaModel.ListarCategoriasHome();

            rptMenu.DataSource = listaCategorias;
            rptMenu.DataBind();
        }

        protected void rptMenu_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                tb_cat_categoria item = (tb_cat_categoria)e.Item.DataItem;

                HyperLink hlLink = (HyperLink)e.Item.FindControl("hlLink");
                HtmlContainerControl dvMenu = (HtmlContainerControl)e.Item.FindControl("dvMenu");

                hlLink.Text = item.cat_des_categoria;
                hlLink.NavigateUrl = "~/" + item.cat_idt_categoria;

                if (item.cat_des_categoria.Equals("SOLDA", StringComparison.CurrentCultureIgnoreCase))
                {
                    dvMenu.Style.Clear();
                    dvMenu.Attributes.Add("class", "bt_soldas");
                }
                else if (item.cat_des_categoria.Equals("MIG|MAG", StringComparison.CurrentCultureIgnoreCase))
                {
                    dvMenu.Style.Clear();
                    dvMenu.Attributes.Add("class", "bt_mig");
                }
                else if (item.cat_des_categoria.Equals("TRACIONADORES", StringComparison.CurrentCultureIgnoreCase))
                {
                    dvMenu.Style.Clear();
                    dvMenu.Attributes.Add("class", "bt_tracionadores");
                }
                else if (item.cat_des_categoria.Equals("PEÇAS", StringComparison.CurrentCultureIgnoreCase))
                {
                    dvMenu.Style.Clear();
                    dvMenu.Attributes.Add("class", "bt_pecas");
                }
                else if (item.cat_des_categoria.Equals("FONTES", StringComparison.CurrentCultureIgnoreCase))
                {
                    dvMenu.Style.Clear();
                    dvMenu.Attributes.Add("class", "bt_fontes");
                }
            }
        }

        protected void lbBuscar_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/default.aspx?q=" + Server.UrlEncode(txtBusca.Text));
        }
    }
}